﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing.Design;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Windows.Forms.Design;

namespace Common.CustomControl {
  public class TextEditor : UITypeEditor {
    public override UITypeEditorEditStyle GetEditStyle(ITypeDescriptorContext context) {
      return UITypeEditorEditStyle.DropDown;
    }

    private bool _isDropDownResizable = false;

    public override bool IsDropDownResizable {
      get {
        return _isDropDownResizable;
      }
    }


    public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value) {
      IWindowsFormsEditorService wfes = provider.GetService(typeof(IWindowsFormsEditorService)) as IWindowsFormsEditorService;
      if (wfes != null) {
        RichTextBox mTextBox = new RichTextBox();
        mTextBox.Multiline = true;
        mTextBox.Height = 100;
        mTextBox.Text = value.ToString();
        mTextBox.Select(mTextBox.Text.Length, 0);
        wfes.DropDownControl(mTextBox);
        value = mTextBox.Text;
      }
      return value;
    }




  }
}
